﻿// Copyright 2013 Ronald Schlenker, www.technewlogic.de.
// 
// This file is part of Byond.
// 
// Byond is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
// 
// Byond is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Byond.  If not, see <http://www.gnu.org/licenses/>.
namespace Utils
{
	public class MathHelper
	{
		///  <summary>
		///  Bildet einen Wert von einer Skala auf eine andere Skala ab.
		///  </summary>
		///  <remarks>
		///  (x1, x2): Wertebereich der Quell-Skala
		///  (y1, y2): Min / Max-Bereich der Ziel-Skala
		/// 
		///  Daraus folgt: P1(x1, y1) und P2(x2, y2)
		/// 
		///  Punktsteigungsform:
		///  y = (y2 - y1) / (x2 - x1) * (x - x1) + y1
		///  </remarks>
		/// <param name="x1">Anfang des Wertebereichs der Quell-Skala</param>
		/// <param name="y1">Anfang des Wertebereichs der Ziel-Skala</param>
		/// <param name="x2">Ende des Wertebereichs der Quell-Skala</param>
		/// <param name="y2">Ende des Wertebereichs der Ziel-Skala</param>
		/// <param name="value">Zu übersetzender Wert</param>
		/// <returns></returns>
		public static double Map(double x1, double y1, double x2, double y2, double value)
		{
			return (y2 - y1) / (x2 - x1) * (value - x1) + y1;
		}
	}
}
